package com.sky.controller;

import com.sky.domain.WmsPurchaseDetail;
import com.sky.service.WmsPurchaseDetailService;
import com.sky.utils.PageUtils;
import com.sky.utils.R;
import com.sky.vo.param.WmsPurchaseDetailVO;
import jakarta.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

@RestController
@RequestMapping("/purchaseDetail")
public class WmsPurchaseDetailController {

    @Resource
    private WmsPurchaseDetailService purchaseDetailService;

    @GetMapping("/page")
    public R page(WmsPurchaseDetailVO vo) {
        PageUtils page = purchaseDetailService.pageQuery(vo);
        return R.ok(page);
    }

    @GetMapping("/getById/{id}")
    public R getById(@PathVariable("id") Long id) {
        WmsPurchaseDetail purchaseDetail = purchaseDetailService.getById(id);
        return R.ok(purchaseDetail);
    }

    @PostMapping("/save")
    public R save(@RequestBody WmsPurchaseDetailVO vo) {
        WmsPurchaseDetail purchaseDetail = new WmsPurchaseDetail();
        BeanUtils.copyProperties(vo, purchaseDetail);
        return purchaseDetailService.save(purchaseDetail) ? R.ok() : R.error();
    }

    @PostMapping("/update")
    public R update(@RequestBody WmsPurchaseDetailVO vo) {
        WmsPurchaseDetail purchaseDetail = new WmsPurchaseDetail();
        BeanUtils.copyProperties(vo, purchaseDetail);
        return purchaseDetailService.updateById(purchaseDetail) ? R.ok() : R.error();
    }

    @DeleteMapping("/delete")
    public R delete(@RequestBody Long[] id) {
        return purchaseDetailService.removeBatchByIds(Arrays.asList(id)) ? R.ok() : R.error();
    }
}
